<template>
	<b-layout-index>
		<navbar :title="title"></navbar>
		<view class="">
			<block v-for="(item,index) in datalist">
				<b-user-agent is-link @action="getResultData" :item="item"></b-user-agent>
			</block>
			<u-empty v-if="datalist.length==0" mode="search">
			</u-empty>
		</view>

	</b-layout-index>
</template>

<script>
	import {
		findByTreeList
	} from "@/api/user.js"

	export default {
		data() {
			return {
				status: 'loadmore',
				// tablist: [{
				// 	name: "全部"
				// }, {
				// 	name: "待审核"
				// }, {
				// 	name: "已审核"
				// }],
				title: this.$t('选择商品'),
				userId: 0,
				current: 1,
				page: 1,
				datalist: []
			}

		},
		onLoad: function(options) {
			console.log(options)
			this.userId = options.id || 0;
			this.title = options.name

			this.findByAgentList()
		},
		onReachBottom: function() {
			console.log("LLLLLL Up")
			if (this.page != -1) {
				//this.datalist = []
				this.page = this.page + 1;
				this.findByAgentList();
			}
		},
		methods: {
			clickShop() {

			},
			findByAgentList() {
				var the = this;
				var param = {
					userId: the.userId || 0,
					current: this.page
				}

				var the = this;

				var datalist = the.datalist;
				findByTreeList(param).then(res => {
					console.log(res)
					if (res.length < 10) {
						the.page = -1;
					}
					if (datalist.length > 0) {
						for (var i = 0; i < res.length; i++) {
							var item = res[i]
							datalist.push(item)
						}
					} else {
						datalist = res;
					}
					console.log(datalist)
					the.datalist = datalist

				})
			},
			getResultData: function(item) {
				console.log(item)
				var name = item.name || item.nickName
				uni.navigateTo({
					url: "./tree?id=" + item.id + "&name=" + name
				})

			}
		}
	}
</script>

<style>
</style>